Append ocument (document; type)  -> Document Ref
                                                                                    Pg 26-3

document           String    Name of file to append to
type                  String    Type of files to display in Open File dialog
Document ref     Time      Reference variable for the document.

Append document opens document, an existing Macintosh document, for writing. Data written to the document is appended to the end of the document .

If document is an empty string (""), a Macintosh Open File dialog box is presented, and the user may specify the document name.

If you use an empty string for document (that is, if the open-file dialog box is presented to the user), you may specify the document type with type, a 4-character string. The Open File dialog box then displays only files of that type. The most common document type is TEXT. If you do not specify type, documents of all types can be opened.

If the user opens a document, the OK system variable is set to 1 and the Document system variable is set to the name of the opened document. Otherwise, the OK system variable is set to 0. If the document is not opened Append document returns a null document reference.

The following example opens an existing document called Note, writes the string "Good-bye" into it, and closes the document. If the document already contained the string "Hello", the string would be overwritten:

vDoc := Open document ("Note")      ` Open a document called Note
If (OK=1)
   SEND PACKET (vDoc; "Good-bye") ` Write 1 word to the document
   CLOSE DOCUMENT (vDoc)              ` Close the document
End if

If the Note document on disk is opened by a word processor, the document will now contain the string "Good-bye."

The following example opens an existing document called Note, appends the string "and so long" and a carriage return onto the end of the document, and closes the document. If the document already contained the string "Good-bye", the document would now contain the string "Good-bye and so long", followed by a carriage return:

Doc := Append document ("Note")      `  Create Note document
SEND PACKET (Doc; " and so long" + Char (13)) ` Append a string
CLOSE DOCUMENT (Doc)                     `  Close the document

See also:    har, Close ocument, Open ocument, 
                 SEND ACKET